<?php


namespace core\entity;


/**
 * 群内用户
 * Class GroupUser
 * @package core\entity
 */
class GroupUser extends User {

    const ROLE_OWNER = 'owner';
    const ROLE_ADMIN = 'admin';
    const ROLE_MEMBER = 'member';

    const PERMISSION_MEMBER = 0;
    const PERMISSION_ADMIN = 1;
    const PERMISSION_OWNER = 2;

    const SEX_MALE = 'male';
    const SEX_FEMALE = 'female';
    const SEX_UNKNOWN = 'unknown';

    /**
     * 群名片
     * @var string
     */
    public $card;

    /**
     * 性别
     * 具体值见常量
     * @var string
     */
    public $sex;

    /**
     * 用户地区
     * @var string
     */
    public $area;

    /**
     * 群内等级
     * @var string
     */
    public $level;

    /**
     * 角色
     * 具体值见常量
     * @var string
     */
    public $role;

    /**
     * 头衔
     * @var string
     */
    public $title;

    /**
     * 权限级别
     * 通过role转换得到
     * @var int
     */
    public $permission;

    /**
     * GroupUser constructor.
     * @param $sender
     */
    public function __construct($sender) {
        parent::__construct($sender);
        static $ROLE_PERMISSION_MAP = [
            self::ROLE_OWNER => self::PERMISSION_OWNER,
            self::ROLE_ADMIN => self::PERMISSION_ADMIN,
            self::ROLE_MEMBER => self::PERMISSION_MEMBER,
        ];
        $this->card = $sender['card'];
        $this->area = $sender['area'];
        $this->level = $sender['level'];
        $this->role = $sender['role'];
        $this->title = $sender['title'];
        $this->permission = $ROLE_PERMISSION_MAP[$this->role];
    }

}
